﻿@page "/system_manager/attachment"
@inherits ListOperateTableBase<AttachmentDto, Guid, AttachmentEdit>
<div>
    <Table @ref="_table"
           TItem="AttachmentDto"
           DataSource="@_datas"
           Total="_total"
           OnChange="@OnChange"
           @bind-PageIndex="_pageIndex"
           @bind-PageSize="_pageSize"
           @bind-SelectedRows="_selectedRows"
           Loading="@_tableLoading.Value"
           Context="model">
        <TitleTemplate>
             <ResourceAuthorize ResourceKey="system_manager_attachment_refresh">
                <TableSearch TDto="AttachmentDto" OnSearch="(filterGroups)=>ReLoadTable(true)" @ref="this.tableSearch" DefaultValue="_defaultSearchValue"></TableSearch>
             </ResourceAuthorize>
            <Row>
                <AntDesign.Col Span="8">
                    <ResourceAuthorize ResourceKey="system_manager_attachment_delete_selected">
                        <Button Type="@ButtonType.Primary" Icon="delete" Danger OnClick="OnClickDeletes" Loading="_deletesBtnLoading">
                            @Localizer[SharedLocalResource.DeleteSelected]
                        </Button>
                    </ResourceAuthorize>
                </AntDesign.Col>
                <AntDesign.Col Span="16" Style="text-align:right">
                        <ResourceAuthorize ResourceKey="system_manager_attachment_refresh">
                                <Button Type="@ButtonType.Primary" Icon="reload" OnClick="ReLoadTable">
                                    @Localizer[SharedLocalResource.Refresh]
                                </Button>
                        </ResourceAuthorize>
                </AntDesign.Col>
            </Row>
        </TitleTemplate>
        <ColumnDefinitions>
            <ResourceAuthorize ResourceKey="system_manager_attachment_delete_selected">
                <Selection Key="@(model.Id.ToString())" />
            </ResourceAuthorize>
            @*<Column @bind-Field="@model.Id" />*@
            <Column @bind-Field="@model.BusinessType" TData="AttachmentBusinessType" Filters="TableFiltersConstants.AttachmentBusinessTypeFilters">
                <TagPro Text="@EnumHelper.GetEnumDescription(model.BusinessType)"></TagPro>
            </Column>
            <Column @bind-Field="@model.BusinessId" Filterable />
            <Column @bind-Field="@model.FileType" TData="AttachmentFileType" Filters="TableFiltersConstants.AttachmentFileTypeFilters">
                <TagPro Text="@EnumHelper.GetEnumDescription(model.FileType)"></TagPro> @model.ContentType
            </Column>
            <Column @bind-Field="@model.Size" Filterable>
                @model.Size B
            </Column>
            @*<Column @bind-Field="@model.Path" />
            <Column @bind-Field="@model.Name" />*@
            <Column @bind-Field="@model.Suffix" Filterable />
            <Column @bind-Field="@model.OriginalName" Style="max-width:200px" Filterable />
            <Column Title="文件" @bind-Field="@model.Url" Filterable>

                @if (model.FileType.Equals(AttachmentFileType.Image))
                {

                    if (model.BusinessType.Equals(AttachmentBusinessType.Avatar))
                    {
                        <Avatar Size="64" Src="@model.Url" />
                    }
                    else
                    {

                        <img src="@model.Url" width="100" height="100" />
                    }
                }
                else
                {
                    <a href="@model.Url" target="_blank">@model.OriginalName</a>
                }

            </Column>
            <Column @bind-Field="@model.CreatedTime" Format="@ClientConstant.DateTimeFormat" Sortable DefaultSortOrder="@SortDirection.Descending" Title="@Localizer[SharedLocalResource.CreatedTime]" />
            <ActionColumn>

                <Space>
                    <ResourceAuthorize ResourceKey="system_manager_attachment_detail">
                        <SpaceItem>
                            <Tooltip Title="@(Localizer[SharedLocalResource.Detail])" ArrowPointAtCenter="true">
                                <Button Icon="eye" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnClickDetail(model.Id)"></Button>
                            </Tooltip>
                        </SpaceItem>
                    </ResourceAuthorize>
                    <ResourceAuthorize ResourceKey="system_manager_attachment_delete">
                        <SpaceItem>
                            <Tooltip Title="@(Localizer[SharedLocalResource.Delete])" ArrowPointAtCenter="true">
                                <Button Icon="delete" Type="@ButtonType.Primary" Danger OnClick="()=>OnClickDelete(model.Id)"></Button>
                            </Tooltip>
                        </SpaceItem>
                    </ResourceAuthorize>
                </Space>
            </ActionColumn>
        </ColumnDefinitions>
    </Table>
</div>